{layout name="layout" /}

<script type="text/javascript" charset="utf-8" src="__JS__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__JS__/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__JS__/ueditor/lang/zh-cn/zh-cn.js"></script>

<form id='form1' name='form1' method='post' action="{:Url('admin/product/updatecheck')}">
    <h2>修改商品</h2>
    <table>
        <tr>
            <td>商品ID</td>
            <td><input type="text" name="pId" readonly value="{$product['pId']}"></td>
        </tr>
        <tr>
            <td>商品类别</td>
            <td>
                <select id="pClassId" name="pClassId" required="true">
                    <option value="">请选择...</option>
                    {foreach name="classes" item="class"} 
                        {if condition="($class['cId']==$product['pClassId'])"}
                            <option value='{$class["cId"]}' selected='selected'>{$class["cName"]}</option>
                        {else /}
                            <option value='{$class["cId"]}'>{$class["cName"]}</option>
                        {/if}
                    {/foreach}
                </select>
            </td>
        </tr>
        <tr>
            <td>商品名称</td>
            <td>
                <input name="pName" type="text" id="pName" size="40" value="{$product['pName']}" required="true" />
            </td>
        </tr>
        <tr>
            <td>商品价格</td>
            <td>
                <input name="pPrice" type="text" id="pPrice" size="40" value="{$product['pPrice']}" required="true" number="true" />
            </td>
        </tr>
        <tr>
            <td>商品图片</td>
            <td>
                <select name='pImg' id='pImg' required="true">
                    <option value="">请选择图片</option>
                    {foreach name="files" item="data"}
                        {if condition="($data!='.') and ($data!='..') "}
                            {if condition="($data==$product['pImg'])"}
                                <option value='{$data}' selected="selected">{$data}</option>
                            {else /}
                                <option value='{$data}'>{$data}</option>
                            {/if}
                        {/if}
                    {/foreach}
                </select>
                <br/>
                <img id='img1' name='img1' width='100px' height='100px' src='__STATIC__/upload/{$product['pImg']}' />
            </td>
        </tr>
        <tr>
            <td>商品简介</td>
            <td>
                <textarea name="pDescr" type="text" id="pDescr" rows="3" cols="40" required="true">
                    {$product['pDescr']}
                </textarea>
            </td>
        </tr>
        <tr>
            <td>商品详情</td>
            <td>
                <script id="pDescrDetail" name="pDescrDetail" type="text/plain" style="width:800px;height:300px;">{$product['pDescrDetail']}</script>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" name="submit" value="修改商品" onclick="return confirm('确定要修改吗？');"/>
            </td>
        </tr>
    </table>
</form>

<script type="text/javascript">
    //实例化编辑器
    var ue = UE.getEditor('pDescrDetail');
    
    //图片选择变化事件
    document.getElementById("pImg").addEventListener("change", function(){
        document.getElementById("img1").src = "__STATIC__/upload/"+this.value;
    });
</script>